package com;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class TeacherMain extends JFrame implements ActionListener{
	
	private JButton[] bt=new JButton[3];
	private static final long serialVersionUID = 1L;
	public TeacherMain() {
		setTitle("教师");
		setVisible(true);
		setSize(500, 100);
		setLocation((Teacher.WIDTH-getWidth())/2, (Teacher.HEIGHT-getHeight())/2);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLayout(null);
		String[] str={"开始广播","停止广播","分发文件"};
		int x=50;
		for(int i=0;i<str.length;i++){
			bt[i]=new JButton(str[i]);
			bt[i].setBounds(x, 20, 100, 25);
			add(bt[i]);
			bt[i].addActionListener(this);
			x+=150;
		}
		bt[1].setEnabled(false);
	}
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				new TeacherMain();
			}
		});
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		Object o=e.getSource();
		if(o==bt[0]){
			Teacher.startCast();
			bt[0].setEnabled(false);
			String s=Teacher.receiveCmd();
			System.out.println(s);
			bt[1].setEnabled(true);
		}
		else if(o==bt[1]){
			Teacher.stopCast();
			bt[1].setEnabled(false);
			String s=Teacher.receiveCmd();
			System.out.println(s);
			bt[0].setEnabled(true);
		}
		else if(o==bt[2]){
			
		}
	}

}
